﻿using System;
using System.Threading;
using smp.RabbitMq;

namespace TestClientsCommon
{
    public class Responder1 : IResponderHandler<RequestMessage1, Response1>
    {
        #region Implementation of IResponderHandler<RequestMessage1,Response1>

        public Response1 Respond(RequestMessage1 message)
        {
            Console.WriteLine("Recieved message from " + message.Name);
            return new Response1 {Message = "Hello " + message.Name + " this is responder handler 1"};
        }

        #endregion
    }

    public class Responder2 : IResponderHandler<RequestMessage1, Response1>
    {
        #region Implementation of IResponderHandler<RequestMessage1,Response1>

        public Response1 Respond(RequestMessage1 message)
        {
            int messageNumber;
            if(int.TryParse(message.Name, out messageNumber))
            {
                if (messageNumber % 2 == 0)
                {
                    Console.WriteLine("Returning response");
                    return new Response1 {Message = "Hello message number " + message.Name};
                }
            }
            Thread.Sleep(6000);
            Console.WriteLine("Timed out response for message " + message.Name);
            return new Response1 {Message = "Timed out response for message " + message.Name};
        }

        #endregion
    }
}
